package eao;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import entity.SocialNetwork;

/**
 * Session Bean implementation class EaoSocialNetwork
 */
@Stateless(mappedName = "eaoSocialNetwork")
@LocalBean
public class EaoSocialNetwork {

	@PersistenceContext
	private EntityManager em;
    /**
     * Default constructor. 
     */
    public EaoSocialNetwork() {
        // TODO Auto-generated constructor stub
    }
    

    public SocialNetwork find(int id) {
        return em.find(SocialNetwork.class, id);
    }

    public List<SocialNetwork> list() {
    	return em.createQuery("SELECT sn FROM SocialNetwork sn", SocialNetwork.class).getResultList();
    }

    public void create(SocialNetwork socialNetwork) throws Exception {
        try{
        	em.persist(socialNetwork);
        	em.flush();
        }catch (Exception e) {
        	throw new Exception(e.getMessage());
		}
    }

    public void update(SocialNetwork socialNetwork) {
        em.merge(socialNetwork);
    }

    public void delete(SocialNetwork socialNetwork) {
        em.remove(em.contains(socialNetwork) ? socialNetwork : em.merge(socialNetwork));
    }

}
